Drupal 6.x Drop-down menu

10 02 2009

For the second time, I was tasked with setting-up a down-down menu in Drupal for the Primary Links. I don’t recall struggling last time, but this time it took a while until I could get it to render properly. I checked the old code, and the menu was shown using the Primary Links block. Instead of adding in blocks and doing it the same way, I thought I could make a few small adjustments to the theme’s template.php

The issue was

  1. The main list needed an id to send to the drop-down config
  2. The child items needed to appear as a sub menu (ul)

Using the $primary_links variable in page.tpl.php doesn’t include the child items, even when Expanded is selected in the Drupal menu config. I tried a number of different theme functions, but nothing seemed to work. What did work finally was calling from the page.tpl.php

print theme('menu_tree','primary-links');

For the id, I used the template.php function:

function phptemplate_menu_tree($tree) {
  $id=strpos($tree,'href="/"')!==FALSE?' id="primarylinks"':'';
  return '<ul class="menu menulist" '.$id.'>'. $tree .'</ul>';
}

There’s probably a better way to do it, but that’s how I got the id for the main menu set to primarylinks, and default for the child menus.

Acknowledgment:  DHTML / JavaScript Menu by TwinHelix Designs


Actions

Information

6 responses

13 03 2009
Scott Fennell

Thank you so much, for some reason its not that obvious what variables are available. (at least -I- have no clue where to look for what variables are available to page.tpl.php)

In any case, this is exactly what I was looking for.

29 04 2009
Eli

Hi, I am trying to apply your code to my site. I have the below code in my page.tpl.php. Can you please be more specific where I could put your code?

29 04 2009
israelwebdev

If it’s working at all, you should see it rendering the list containing the menu. Place the code in the part of the page where you want the menu to appear. Style to taste and serve.

5 06 2009
Anne

I’m new to Drupal here. I was wondering does this work for only specific kinds of templates or should this work for all templates? Thanks and great tutorial!

7 06 2009
israelwebdev

This should work for all node templates for Drupal 6.x

24 04 2010
Sudeep Goyal

Thanks Zvi for the great help. Drupal 6 Menu theming information seems scanty on the web. I wrote this tutorial on how to theme drupal 6 menus. I took help from this page as well. thanks.
– Sudeep Drupal based product development and theming, US, India

Leave a comment